package com.group4.datafactorybackend.controller;

import com.group4.datafactorybackend.common.R;
import com.group4.datafactorybackend.common.enums.ResultCodeEnum;
import com.group4.datafactorybackend.entity.DTO.CreateOrUpdateDirectoryDTO;
import com.group4.datafactorybackend.entity.VO.DirectoryVO;
import com.group4.datafactorybackend.service.DirectoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 卑微小峰
 * @date 2022/8/1
 */
@RestController
@Api(tags = "目录管理")
@RequestMapping("/directory")
public class DirectoryController {

    private final DirectoryService directoryService;

    @Autowired
    public DirectoryController(DirectoryService directoryService) {
        this.directoryService = directoryService;
    }

    /**
     * @author 卑微小峰
     * @param createOrUpdateDirectoryDTO 新增、修改目录接收参数实体类
     * @return R
     * @description 新增目录
     */
    @ApiOperation("新增目录")
    @PostMapping("/post/addDirectory")
    public R<?> addDirectory(@RequestBody CreateOrUpdateDirectoryDTO createOrUpdateDirectoryDTO) {
        return directoryService.addDirectory(createOrUpdateDirectoryDTO);
    }

    /**
     * @author 卑微小峰
     * @param directoryCode 删除的目录编号
     * @return R
     * @description 删除目录
     */
    @ApiOperation("删除目录")
    @DeleteMapping("/delete/deleteDirectory/{directoryCode}")
    public R<?> deleteDirectory(@PathVariable("directoryCode")String directoryCode) {
        return directoryService.deleteDirectory(directoryCode);
    }

    /**
     * @author 卑微小峰
     * @param createOrUpdateDirectoryDTO 编辑目录接收参数DTO
     * @return R
     * @description 编辑目录
     */
    @ApiOperation("编辑目录")
    @PutMapping("/update/updateDirectory")
    public R<?> updateDirectory(@RequestBody CreateOrUpdateDirectoryDTO createOrUpdateDirectoryDTO) {
        return directoryService.updateDirectory(createOrUpdateDirectoryDTO);
    }

    /**
     * @author 卑微小峰
     * @param menuCode 菜单编号
     * @return R
     * @description 获取目录列表
     */
    @ApiOperation("获取目录列表")
    @GetMapping("/get/getDirectoryList/{menuCode}")
    public R<?> getDirectoryList(@PathVariable("menuCode")Integer menuCode) {
        List<DirectoryVO> directoryList = directoryService.getDirectoryList(menuCode.toString());
        return R.Success(ResultCodeEnum.SUCCESS, directoryList);
    }
}
